//页面加载完毕执行
$(function(){
	//$("#mymodal").modal();
	findAllTeachers();
	
});

function findAllTeachers(){
	var url = "/jingsaiguanli/teacher?method=findAllTeachers";
	$.post(url,function(data){
		var jsonObj = eval(data);
		var html = "";
		for(var i=0;i<jsonObj.length;i++){

			if(jsonObj[i].t_state==0){
				html+="<tr><td class='col-md-1'>"+(i+1)+"</td> <td id='t_name"+((jsonObj[i]).t_id)+"'> "+(jsonObj[i].t_name)+" </td> <td>"+(jsonObj[i].t_xueyuan)+"</td> <td>"+(jsonObj[i].t_email)+"</td><td> <a href='javascript:void(0)' onclick=findTeacherById("+(jsonObj[i]).t_id+")>编辑</td><td> <a href='javascript:void(0)' onclick=delete("+(jsonObj[i]).t_id+")>删除</td> <td> </td></tr>";
			}else{
				html+="<tr class='danger'><td class='col-md-1'>"+(i+1)+"</td> <td id='t_name"+((jsonObj[i]).t_id)+"'> "+(jsonObj[i].t_name)+" </td><td>"+(jsonObj[i].t_xueyuan)+"</td><td>"+(jsonObj[i].t_email)+"</td><td> <a href='javascript:void(0)' onclick=findTeacherById("+(jsonObj[i]).t_id+")>编辑</td><td> <a href='javascript:void(0)' onclick=delete("+(jsonObj[i]).t_id+")>删除</td><td> <a href='javascript:void(0)' onclick=shenhe("+(jsonObj[i]).t_id+")>审核通过</td></tr>";
			}
			
		}
		$("#pbody").html(html);
	},"json");
}

/**
 * 通过id修改老师的记录
 * @param id
 * @returns
 */
function findTeacherById(id){
	
	var url = "/jingsaiguanli/teacher?method=findTeacherById";
	$.post(url,{"t_id":id},function(data){
		var jsonObj = eval("("+data+")");
		$("#mymodal").modal('show');
		
		$("#t_name").val(jsonObj.t_name);
		$("#t_password").val(jsonObj.t_password);
		$("#t_xueyuan").val(jsonObj.t_xueyuan);
		
		$("#editTeacher").unbind("click");
		//点击修改按钮进行修改
		$("#editTeacher").bind("click",function(){
			//得到表单数据
			//var t_name = $("#t_name").val(); 教师名不能修改
			var t_password = $("#t_password").val();
			var t_xueyuan = $("#t_xueyuan").val();
			var t_id = id;
			$.post("/jingsaiguanli/teacher?method=editTeacherById",{"t_password":t_password,"t_xueyuan":t_xueyuan,"t_id":t_id},function(data){
				//关闭编辑窗口
				$("mymodal").modal('hide');
				//查询教师信息
				findAllTeachers();
			});
		});
	});
	
}